import Vue from 'vue'
import App from './App.vue'
import store from './store'
import "normalize.css/normalize.css"

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import axios from "axios"
import utils from "@/common/Utils"

Vue.config.productionTip = false
Vue.use(ElementUI)

const init = () => {
    new Vue({
        store,
        render: h => h(App)
    }).$mount('#app')
}

let needWait = false

const userInfo = localStorage.getItem('userInfo')
if (userInfo) {
    needWait = true
    const user = JSON.parse(userInfo)
    axios.post(
        utils.getFullURL('/user/_hasUser'),
        user
    ).then((resp) => {
        if (resp.data === 1) {
            store.commit('setUserInfo', user)
        } else {
            store.commit('clearUserInfo')
        }
        init()
    }).catch(reson => {
        alert('网站异常，请刷新重试，或联系管理员')
    })
}

if (!needWait) {
    init()
}






